import { PageConfig } from 'next';
import anylogger from 'anylogger';
import '@mmstudio/an000042';
import an48 from '@mmstudio/an000048';
import { tbjob, tbs_job_ment } from '../../../../atoms/db';

const logger = anylogger('pages/api/zllweapp/workpush/s001.api');

export type Result = {
	ok: true;
} | {
	ok: false;
	message: string;
};
export type Message = {
	sjobcontent: string;
	uploadedfile: string;
	uploadedfile1: string;
	id: string;
}


/**
 * pages/api/zllweapp/workpush/s001.api
 */
const handler = an48<Result>();

handler.post(async (req, res) => {
	try {
		logger.debug('msg body:', req.body);
		const { sjobcontent, uploadedfile, uploadedfile1, id } = req.body as Message;
		//**获取用户学生学号 */ 张三
		const student_id = '201942908581';
		if (uploadedfile) {
			await tbs_job_ment().update({
				s_picture: uploadedfile
			}).where({
				job_id: id,
				student_id: student_id
			});
		}
		if (uploadedfile1) {
			await tbs_job_ment().update({
				s_picture: uploadedfile1
			}).where({
				job_id: id,
				student_id: student_id
			});
		}
		if (sjobcontent) {
			await tbjob().update({
				s_jobcontext: sjobcontent
			}).where({
				job_id: id,
				student_id: student_id
			});
		}


		res.status(200).json({ ok: true });
	} catch (error) {
		logger.trace(error);
		res.status(200).json({ ok: false, message: (error as Error).message });
	}
});

export const config = {} as PageConfig;

export default handler;
